package org.example.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.example.common.handle.MqttServiceHandle;
import org.example.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 李荣
 * @Date 2025/1/20
 * @Description
 */
@Service
@Slf4j
public class WebSocketServiceImpl implements WebSocketService {

    private final String topic = "receive-switch-status";

    @Autowired
    private MqttServiceHandle mqttServiceHandle;

    @Override
    public void handle(Integer message) {
        try {
            mqttServiceHandle.publish(String.valueOf(message),topic);
        } catch (MqttException e) {
            e.printStackTrace();
            log.info("消息发送失败，请检查失败的原因");
        }
    }
}
